#include "character.h"


SE_character *SE_character_init()
{

	SE_character *chara;
	chara = (SE_character*)malloc(sizeof(SE_character));
	chara->numsprites = 0;
	chara->currentspr = 0; 

	
	return chara;

}

void SE_character_addsprite(SE_character *chara,SE_sprite *spr)
{
		SE_sprite** temp;
		chara->numsprites++; 
//		temp = (SE_sprite**)realloc(chara->spr,chara->numsprites * sizeof(SE_sprite*));
		temp = (SE_sprite**)malloc(chara->numsprites * sizeof(SE_sprite*));
		if(temp!=NULL){
			memcpy(temp,chara->spr,(chara->numsprites-1) * sizeof(SE_sprite*));
			chara->spr=temp;
			chara->spr[chara->numsprites - 1] = spr;
		}else{
			printf("error en realloc\n");
		}
		
}




void SE_character_currentsprite(SE_character *chara,int currentsprite)
{
	if((currentsprite < chara->numsprites)&&(currentsprite >= 0))
	{	
		chara->currentspr = currentsprite;
	}
}

void SE_character_draw_effects(SE_character *chara,float posx,float posy,float posz,float zoomx,float zoomy,float rotx,float roty,float rotz,float r,float g,float b,float alpha)
{


		SE_sprite_draw_effects(chara->spr[chara->currentspr],posx,posy,posz,zoomx,zoomy,rotx,roty,rotz,r,g,b,alpha);

}

void SE_character_draw(SE_character *chara,float posx,float posy,float posz)
{

	SE_character_draw_effects(chara,posx,posy,posz,1,1,0,0,0,1,1,1,1);

}

void SE_character_drawbox(SE_character *chara,float posx,float posy)
{

	SE_sprite_drawbox(chara->spr[chara->currentspr],posx,posy);

}

void SE_character_clean(SE_character *chara)
{
	int i;
	int nsprite = chara->numsprites;
	for(i = 0;i < nsprite;i++)
	{
		chara->spr[i]=NULL;
		printf("%d",chara->spr[i]);
	}

	free(chara->spr);
	chara->spr=NULL;

	free(chara);
	chara=NULL;


	if(chara != 0)
	{
		printf("error, no se pudo borrar puntero de character");
	}


}
